package refactoringtechniques;

import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JComboBox;

import javax.swing.JList;
import junit.framework.Assert;

public class GeneralComboBoxListenerTester {

    @org.junit.Test public void testAddItemToComboBox() {

        JComboBox codeSmells = new JComboBox();
        codeSmells.setModel(new DefaultComboBoxModel());
        JComboBox codeSmellGroups = new JComboBox();
        codeSmellGroups.setModel(new DefaultComboBoxModel());
        JList refactorings = new JList();
        refactorings.setModel(new DefaultListModel());

        Main.GeneralComboBoxListener fixture = new Main.GeneralComboBoxListener(codeSmells, codeSmellGroups, refactorings);
        String[] items = { "item1", "item2" };
        fixture.addItems(codeSmells, items);
        Assert.assertEquals(2, codeSmells.getItemCount());
    }

    @org.junit.Test public void TestAddNullListControl()
    {
        JComboBox codeSmells = new JComboBox();
        codeSmells.setModel(new DefaultComboBoxModel());
        JComboBox codeSmellGroups = new JComboBox();
        codeSmellGroups.setModel(new DefaultComboBoxModel());
        JList refactorings = new JList();
        refactorings.setModel(new DefaultListModel());

        Main.GeneralComboBoxListener fixture = new Main.GeneralComboBoxListener(codeSmells, codeSmellGroups, refactorings);
        String[] items = { "item1", "item2" };
        fixture.addItems(null, items);
    }


    @org.junit.Test public void TestAddNullItems()
    {
        JComboBox codeSmells = new JComboBox();
        codeSmells.setModel(new DefaultComboBoxModel());
        JComboBox codeSmellGroups = new JComboBox();
        codeSmellGroups.setModel(new DefaultComboBoxModel());
        JList refactorings = new JList();
        refactorings.setModel(new DefaultListModel());

        Main.GeneralComboBoxListener fixture = new Main.GeneralComboBoxListener(codeSmells, codeSmellGroups, refactorings);
        String[] items = { "item1", "item2" };

        try {
            fixture.addItems(null, items);
        } catch (NullPointerException e) {
            Assert.fail();
        }
    }

    @org.junit.Test public void testAddItemsToListBox() {

        JComboBox codeSmells = new JComboBox();
        codeSmells.setModel(new DefaultComboBoxModel());
        JComboBox codeSmellGroups = new JComboBox();
        codeSmellGroups.setModel(new DefaultComboBoxModel());
        JList refactorings = new JList();
        refactorings.setModel(new DefaultListModel());

        Main.GeneralComboBoxListener fixture = new Main.GeneralComboBoxListener(codeSmells, codeSmellGroups, refactorings);
        
        try {
            fixture.addItems(refactorings, null);
        } catch (NullPointerException e) {
            Assert.fail();
        }
    }

}
